package com.ziyun.erp.web.modules.quotePrint.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

//import com.utility.StringUtils;
import com.ziyun.erp.common.utils.UserUtils;
import io.renren.common.validator.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.erp.modules.quotePrint.entity.QuotePrintEntity;
import com.ziyun.erp.modules.quotePrint.service.QuotePrintService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 印刷机配置表
 *
 * @author xueqz
 * @email 
 * @date 2018-09-05 16:36:44
 */
@RestController
@RequestMapping("quotePrint/quoteprint")
public class QuotePrintController {
    @Autowired
    private QuotePrintService quotePrintService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quotePrint:quoteprint:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = quotePrintService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("quotePrint:quoteprint:info")
    public R info(@PathVariable("id") Integer id){
        QuotePrintEntity quotePrint = quotePrintService.selectById(id);

        return R.ok().put("quotePrint", quotePrint);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("quotePrint:quoteprint:save")
    public R save(@RequestBody QuotePrintEntity quotePrint){
        quotePrint.setCreateDate(new Date());
        quotePrint.setCreateUser(UserUtils.getCurentUser().getUsername());
        quotePrintService.insert(quotePrint);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("quotePrint:quoteprint:update")
    public R update(@RequestBody QuotePrintEntity quotePrint){
        ValidatorUtils.validateEntity(quotePrint);
        quotePrintService.updateAllColumnById(quotePrint);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("quotePrint:quoteprint:delete")
    public R delete(@RequestBody Integer[] ids){
//        quotePrintService.deleteBatchIds(Arrays.asList(ids));

        quotePrintService.flagDel(StringUtils.join(ids,","));

        return R.ok();
    }

}
